package com.dashu.authority.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dashu.authority.common.Constant;
import com.dashu.authority.entity.Application;
import com.dashu.authority.exception.AuthorityException;
import com.dashu.authority.servie.ApplicationService;
import com.dashu.authority.util.ResultBean;
import com.dashu.authority.util.ResultMsgUtil;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/application")
public class ApplicationController extends BaseController{
	
	
	@Resource
	private ApplicationService applicationService;
	
	@RequestMapping("/findAllByPaging")
	public @ResponseBody Object findAllByPaging(Application entity,Integer page,Integer rows)throws AuthorityException{
		List<Application> returnList=applicationService.queryAllByExample(entity, page, rows);
		Map<String, Object> returnMap = ResultMsgUtil.datagridFormat(new PageInfo<Application>(returnList));
		return new ResultBean(Constant.STATUS_NORMAL,returnMap).getResultMap();
	}
	
	@RequestMapping(value = "/save")
	public @ResponseBody Object addApplication(Application entity) throws AuthorityException {  	
    	Map<String, Object>  returnMap =  applicationService.insertEntity( entity );
		return new ResultBean(returnMap).getResultMap();
    }

    @RequestMapping( value = "/update" )
    public @ResponseBody Object updateApplication(Application entity)  throws AuthorityException {  	
    	Map<String, Object> returnMap = applicationService.updateEntity(entity);
		return new ResultBean(returnMap).getResultMap();
    }


    @RequestMapping( value = "/deleteByIds" )
    public @ResponseBody Object deleteByIds(@RequestParam(value = "ids") Integer[] ids)  throws AuthorityException {    	
		Map<String, Object> returnMap = applicationService.deleteByIds(ids);
		return new ResultBean(returnMap).getResultMap();
    }
    
    @RequestMapping( value = "/updateStatus" )
    public @ResponseBody Object updateStatus(@RequestParam(value = "ids") Integer[] ids,String status)  throws AuthorityException { 
    	Map<String, Object> returnMap = applicationService.updateStatus(ids,status);
		return new ResultBean(returnMap).getResultMap();
    }
}
